#include "DashboardUI_PatientSelect.h"
#include "ui_dashboard_patientselect.h"

#include "Authentication.h"

#include "Nurse.h"
#include "PatientListModel.h"

#include "PersonDatabase.h"
#include "UserRelationDatabase.h"

DashboardUI_PatientSelect::DashboardUI_PatientSelect(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DashboardUI_PatientSelect)
{
    ui->setupUi(this);

    reload();
}

void DashboardUI_PatientSelect::reload()
{
    User * currentUser = Authentication::getInstance()->getUser();

    model.loadRelated(currentUser->getId());

    ui->patientListView->reset();
    ui->patientListView->setModel(&model);

}

DashboardUI_PatientSelect::~DashboardUI_PatientSelect()
{
    delete ui;
}


void DashboardUI_PatientSelect::on_patientListView_clicked(const QModelIndex &index)
{
    int id = index.data(Qt::UserRole).toInt();

    Authentication::getInstance()->setPatient(id);

    emit userChanged();
}
